package de.tabuma.soapforms.shopping;

import de.tabuma.shopping.entity.*;
import java.util.*;
import de.tabuma.soapforms.*;

/**
 * Facade for Shopping
 * @author$
 * @version$
 * @since$
 * @see de.tabuma.shopping.logik.LicensePackageFacade
 */
public class ShoppingFacade implements de.tabuma.shopping.logik.LicensePackageFacade {
    public static double getPrice(int licenseCount, double licensePrice, double asset) {
        double price = (licenseCount*licensePrice*(1+asset));
        price += 0.35;
        double newprice = price;
        for(int i=0;i<10;i++) {
            newprice = newprice * 0.039 + newprice * de.tabuma.shopping.constants.vat/100;
            price += newprice;
        }

        return price;
    }

    private License license11 = new License(1, 50, constants.SOAP_FORM_LICENSE, 0);
    private License license12 = new License(2, 100, constants.SOAP_FORM_LICENSE, 0);
    private License license13 = new License(3, 250, constants.SOAP_FORM_LICENSE, 0);
    private License license14 = new License(4, 500, constants.SOAP_FORM_LICENSE, 0);
    private License license15 = new License(5, 1000, constants.SOAP_FORM_LICENSE, 0);
    private License license16 = new License(5, 5000, constants.SOAP_FORM_LICENSE, 0);

    private License[] l11 = {license11};
    private License[] l12 = {license12};
    private License[] l13 = {license13};
    private License[] l14 = {license14};
    private License[] l15 = {license15};
    private License[] l16 = {license16};
    
    private LicensePackage currentLicensePackageList[] = {
        new LicensePackage(new Long(1), "Soap Forms 50","License for login in a created plattform 100 times.", getPrice(50,0.01,2) , l11 ),
        new LicensePackage(new Long(2), "Soap Forms 100","License for login in a created plattform 1000 times.", getPrice(100,0.01,1.5) , l12),
        new LicensePackage(new Long(3), "Soap Forms 250","License for login in a created plattform 5000 times.", getPrice(250,0.01,1.25), l13),
        new LicensePackage(new Long(4), "Soap Forms 500","License for login in a created plattform 5000 times.", getPrice(500,0.02,1), l14),
        new LicensePackage(new Long(5), "Soap Forms 1000","License for login in a created plattform 5000 times.", getPrice(1000,0.02,0.75), l15),
        new LicensePackage(new Long(6), "Soap Forms 5000","License for login in a created plattform 5000 times.", getPrice(5000,0.02,0.5), l16)
    };

    private static final LicensePackage oldLicensePackageList[] = {};

    public List<LicensePackage> getCurrentLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<currentLicensePackageList.length;i++) {
            list.add(currentLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getOldLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<oldLicensePackageList.length;i++) {
            list.add(oldLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getAllLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        list.addAll(getCurrentLicensePackageList());
        list.addAll(getOldLicensePackageList());
        return list;
    }

    public LicensePackage getLicensePackageWithID(int id) {
        for(int i=0;i<currentLicensePackageList.length;i++) {
            if(currentLicensePackageList[i].getId()==id) {
                return currentLicensePackageList[i];
            }
        }
        for(int i=0;i<oldLicensePackageList.length;i++) {
            if(oldLicensePackageList[i].getId()==id) {
                return oldLicensePackageList[i];
            }
        }
        return null;
    }
}
